
package com.library.uiframework.utils;


public class Log {
    static boolean DEBUG = true;
    public static final String TAG = "TeachIn";

    public Log() {
    }

    /**
     * Send a VERBOSE log message.
     *
     * @param msg The message you would like logged.
     */
    public static void v(String tag, String msg) {
        if (DEBUG)
            android.util.Log.v(TAG+":"+tag, buildMessage(msg));
    }

    /**
     * Send a VERBOSE log message and log the exception.
     *
     * @param msg The message you would like logged.
     * @param throwable An exception to log
     */
    public static void v(String tag, String msg, Throwable throwable) {
        if (DEBUG)
            android.util.Log.v(TAG+":"+tag, buildMessage(msg), throwable);
    }

    /**
     * Send a DEBGU log message.
     *
     * @param msg The message you would like logged.
     */
    public static void d(String tag, String msg) {
        if (DEBUG)
            android.util.Log.d(TAG+":"+tag, buildMessage(msg));
    }

    /**
     * Send a DEBGU log message and log the exception.
     *
     * @param msg The message you would like logge,d.
     * @param throwable An exception to log
     */
    public static void d(String tag, String msg, Throwable throwable) {
        if (DEBUG)
            android.util.Log.d(TAG +":"+tag, buildMessage(msg), throwable);
    }

    /**
     * Send a INFO log message.
     *
     * @param msg The message you would like logged.
     */
    public static void i(String tag, String msg) {
        if (DEBUG)
            android.util.Log.i(TAG+":"+tag, buildMessage(msg));
    }

    /**
     * Send a INFO log message and log the exception.
     *
     * @param msg The message you would like logged.
     * @param throwable An exception to log
     */
    public static void i(String tag, String msg, Throwable throwable) {
        if (DEBUG)
            android.util.Log.i(TAG+":"+tag, buildMessage(msg), throwable);
    }

    /**
     * Send a WARN log message.
     *
     * @param msg The message you would like logged.
     */
    public static void w(String tag, String msg) {
        if (DEBUG)
            android.util.Log.w(TAG+":"+tag, buildMessage(msg));
    }

    /**
     * Send a WARN log message and log the exception.
     *
     * @param msg The message you would like logged.
     * @param throwable An exception to log
     */
    public static void w(String tag, String msg, Throwable throwable) {
        if (DEBUG)
            android.util.Log.w(TAG+":"+tag, buildMessage(msg), throwable);
    }

    /**
     * Send an ERROR log message and log the exception.
     *
     * @param msg The message you would like logged.
     */
    public static void e(String tag, String msg) {
        if (DEBUG)
            android.util.Log.e(TAG+":"+tag, buildMessage(msg));
    }

    /**
     * Send an ERROR log message and log the exception.
     *
     * @param msg The message you would like logged.
     * @param throwable An exception to log
     */
    public static void e(String tag, String msg, Throwable throwable) {
        if (DEBUG)
            android.util.Log.e(TAG+":"+tag, buildMessage(msg), throwable);
    }

    /**
     * Building Message
     *
     * @param msg The message you would like logged.
     * @return Message String
     */
    private static String buildMessage(String msg) {
        StackTraceElement caller = new Throwable().fillInStackTrace().getStackTrace()[2];

        return new StringBuilder().append(caller.getClassName()).append(".")
            .append(caller.getMethodName()).append("()::").append(msg).toString();
    }
}
